/*
 * @(#)MPQueryConfigConstructor.java
 * Date 2013-10-15
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package us.hornerscorners.lamppost.mpq.inject;

import org.yaml.snakeyaml.constructor.Constructor;

import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.Tag;

import us.hornerscorners.lamppost.mpq.constant.MPQueryName;


/**
 * Class description
 *
 *
 * @version        v1.0, 2013-10-15
 * @author         Jim Horner
 */
public class MPQueryConfigConstructor extends Constructor {

    /**
     * Constructs ...
     *
     */
    public MPQueryConfigConstructor() {

        super();

        this.yamlConstructors.put(new Tag("!method"), new ConstructMethodName());
    }

    /**
     * Class description
     *
     *
     * @version        v1.0, 2013-10-15
     * @author         Jim Horner
     */
    private class ConstructMethodName extends ConstructScalar {

        /**
         * Constructs ...
         *
         *
         */
        public ConstructMethodName() {

            super();
        }

        /**
         * Method description
         *
         *
         * @param node
         *
         * @return
         */
        @Override
        public Object construct(Node node) {

            node.setType(MPQueryName.class);

            MPQueryName result = (MPQueryName) super.construct(node);

            if (result == null) {

                String msg = String.format("Node %s contains invalid QueryName.",
                                           node.toString());

                throw new IllegalArgumentException(msg);
            }

            return result;
        }
    }
}
